<template>
  <!-- 从业人员详情页 -->
  <view class="staffDetails">
    <view class="wrapper">
      <view class="wrapper-item">
        <view class="wrapper-bar">
          <view class="wrapper-bartitle">
            <!-- <image :src="baseImgUrl + 'qi-icon.png'" mode=""></image> -->
            {{ detail.companyMessageName }}
          </view>
        </view>
        <view style="padding-top: 20rpx"><u-line></u-line></view>

        <view class="wrapper-body">
          <view class="text-picture">
            <view class="lt">
              <image :src="
                  detail.personImage
                    ? imgPrefix + detail.personImage
                    : baseImgUrl + 'queryFace-01.png'
                " mode="aspectFill"></image>
            </view>
            <view class="rt">
              <view class="wrapper-facility">
                <view class="facility-item">
                  <view class="name">
                    {{ detail.personName }}
                    <!-- <text class="job">{{ options.position }}</text> -->
                  </view>
                </view>
                <view class="facility-item">
                  <view class="label-wrapper">
                    <view class="textAlign label z-text-end-both-align">民族</view>:
                  </view>
                  <view class="value">
                    {{ detail.nationName ? detail.nationName : '暂无' }}
                  </view>
                </view>
                <view class="facility-item">
                  <view class="label-wrapper">
                    <view class="textAlign label z-text-end-both-align">手机号码</view>:
                  </view>
                  <view class="value">
                    {{ detail.mobile }}
                  </view>
                </view>
                <view class="facility-item" v-if="paiNew">
                  <view class="label-wrapper">
                    <view class="textAlign label z-text-end-both-align">身份证号</view>:
                  </view>
                  <view class="value">
                    {{ detail.idCard ? hiddenInfo(detail.idCard, 6, 4) : "" }}
                  </view>
                </view>
                <view class="facility-item">
                  <view class="label-wrapper">
                    <view class="textAlign label z-text-end-both-align">证件照片</view>:
                  </view>
                  <view class="value blueLook" @click="pvwImage([imgPrefix + detail.idCardUrl])"
                    v-if="detail.idCardUrl">
                    查看照片
                  </view>
                  <view class="value" v-else>
                    暂无
                  </view>
                </view>
              </view>
            </view>
          </view>

          <view class="wrapper-facility" style="margin-top: 20rpx">
            <view class="facility-item">
              <view class="label-wrapper">
                <view class="textAlign label">在职时间</view>:
              </view>
              <view class="value">
                {{ formatters(detail.entryTime, "wordDay") || "" }}至
                {{
                  detail.departTime
                    ? formatters(detail.departTime, "wordDay")
                    : "今"
                }}
              </view>
            </view>
            <view class="facility-item">
              <view class="label-wrapper">
                <view class="textAlign label">采集人</view>:
              </view>
              <view class="value">
                {{ detail.collectionName }}
              </view>
            </view>
            <view class="facility-item">
              <view class="label-wrapper">
                <view class="textAlign label">采集人类型</view>:
              </view>
              <view class="value">
                {{ detail.collectionType }}
              </view>
            </view>
          </view>
        </view>
      </view>

      <!-- <view class="wrapper-item">
        <view class="wrapper-bar">
          <view class="wrapper-bartitle"> 健康证信息： </view>
        </view>

        <view class="wrapper-body">
          <view class="wrapper-facility">
            <view class="facility-item">
              <view class="textAlign label"> 发证日期： </view>
              <view class="value">
                {{
                  detail.healthTime
                    ? formatters(detail.healthTime, "wordDay")
                    : "无"
                }}
              </view>
            </view>
            <view class="facility-item">
              <view class="textAlign label"> 有效期： </view>
              <view class="value">
                {{
                  formatters(detail.healthValidityPeriod, "wordDay") || "一年"
                }}
              </view>
            </view>
            <view class="facility-item" v-if="paiNew">
              <view class="textAlign label"> 证件照片： </view>
              <view class="value" :class="detail.healthImage ? 'blueLook' : ''"
                @click="pvwImage([imgPrefix + detail.healthImage])">
                {{ detail.healthImage ? "查看照片" : "无" }}
              </view>
            </view>
          </view>
        </view>
      </view> -->
    </view>

    <view class="btns" v-if="!detail.departTime">
      <button class="remove-btn lt" type="primary" @click="cellTimeClick('delete')">
        移除
      </button>
      <button class="lookbtn" type="primary" :data-url="`/featureFun/staffNewEditor/staffNewEditor?id=${
          options.id
        }&num=${2}&companyMessageId=${options.companyMessageId}&position=${
          options.position
        }`" @click="handleClickRouter">
        编辑
      </button>
    </view>

    <!-- 时间选择器 -->
    <u-datetime-picker ref="datetimePicker" :show="datetimeShow" v-model="timeValue" mode="date" :title="titleDate"
      :formatter="formatter" :minDate="minDate" :maxDate="maxDate" @close="pickerTimeClose" @cancel="pickerTimeClose(1)"
      @confirm="showTimeConfirm" :closeOnClickOverlay="true"></u-datetime-picker>
  </view>
</template>

<script>
  import {
    employeesDetail,
    employeesRemove
  } from "@/api/home.js";
  import {
    handleClickRouter,
    formatters,
    hiddenInfo,
    pvwImage,
    Toast,
    navBack,
  } from "@/utils/util.js";
  import mixin from "@/utils/mixin.js";
  import {
    dayTurnTime
  } from "../../utils/util";

  export default {
    name: "staffDetails",
    mixins: [mixin],
    data() {
      return {
        baseImgUrl: this.$baseImgUrl,
        paiNew: uni.getStorageSync("paiNew"),
        imgPrefix: uni.getStorageSync("imgPrefix"),
        options: {},
        detail: {},
        titleDate: "选择离职时间",
      };
    },
    onLoad(options) {
      this.options = options;
      this.getList();
    },
    methods: {
      handleClickRouter,
      formatters,
      hiddenInfo,
      pvwImage,
      formatter(type, value) {
        if (type === "year") {
          return `${value}年`;
        }
        if (type === "month") {
          return `${value}月`;
        }
        if (type === "day") {
          return `${value}日`;
        }
        return value;
      },
      cellTimeClick(e) {
        this.cellType = e;
        var minDateNum = +new Date(); //获取当前时间的毫秒数

        switch (this.cellType) {
          case "delete":
            this.minDate = dayTurnTime(this.detail.entryTime);
            this.maxDate = minDateNum;
            this.timeValue = this.maxDate;
            break;

          default:
            break;
        }

        setTimeout(() => {
          this.datetimeShow = true;
        }, 100);
      },
      pickerTimeClose(e) {
        this.datetimeShow = false;
      },
      /* 时间选择器 确定 */
      showTimeConfirm(e) {
        let arr = e.value;
        if (arr) {
          switch (this.cellType) {
            case "delete":
              employeesRemove(this.detail.id, arr).then((res) => {
                if (res.code == 200) {
                  Toast("删除成功");
                  navBack();
                }
              });
              break;
            default:
              break;
          }
        }
        this.datetimeShow = false;
      },
      getList() {
        employeesDetail({
          id: this.options.id
        }).then((res) => {
          if (res.code == 200) {
            this.detail = res.result;
          }
        });
      },
    },
  };
</script>

<style>
  page {
    background-color: #f3f3f3 !important;
    height: 100%;
  }
</style>
<style lang="scss" scoped>
  .staffDetails {
    flex: 1;

    .wrapper {
      height: calc(100vh - 71px);
      background: #f8f9fb;
      overflow-y: auto;

      .label-wrapper {
        color: #a1a1a1;
        font-size: 26rpx;
      }

      .value {
        margin-left: 16rpx;
      }

      .wrapper-item {
        margin: 0 20rpx;
        padding: 30rpx 40rpx;
        background-color: #ffffff;
        margin-bottom: 20rpx;

        .wrapper-bar {
          display: flex;
          justify-content: space-between;
          height: 40rpx;

          .wrapper-bartitle {
            font-size: 30rpx;
            font-weight: bold;

            text {
              display: inline-block;
              margin-left: 8px;
              color: #ababab;
              font-size: 28rpx;
            }

            image {
              margin-bottom: -3rpx;
              margin-right: 10rpx;
              width: 36rpx;
              height: 36rpx;
            }
          }
        }

        .wrapper-body {
          padding-top: 20px;
        }

        .text-picture {
          display: flex;

          .lt {
            width: 200rpx;
            height: 220rpx;
            margin-right: 20rpx;

            image {
              width: 100%;
              height: 100%;
            }
          }

          .rt {
            width: 425rpx;
            max-width: 425rpx;

            .name {
              font-size: 36rpx;
              font-family: PingFang SC;
              font-weight: bold;
            }

            .job {
              display: inline-block;
              margin-left: 10rpx;
              padding: 2rpx 15rpx;
              font-size: 26rpx;
              font-weight: 500;
              color: #2488f5;
              background: #d8f2ff;
              border-radius: 16rpx;
            }
          }
        }

        .heaImg {
          width: 625rpx;
        }
      }
    }

    .blueLook {
      color: #2488f5;
    }

    .btns {
      button {
        border-radius: 44rpx;
      }
    }
  }
</style>